package top.swimmer.tools.data.linked;

public class MiddleNode {
    public static ListNode middleNode(ListNode node) {
        if (node == null || node.next == null) {
            return node;
        }
        ListNode first = node;
        ListNode second = node;

        while (first != null && first.next != null) {
            first = first.next.next;
            second = second.next;
        }

        return second;
    }

    public static void main(String[] args) {
        System.out.println(middleNode(ListNode.getTwo()));
    }
}
